#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
    char buffer[16];
    int fd;
    int ret;

    fd = open(argv[1], O_RDWR|O_APPEND);
    if(-1 == fd){
        perror("open error");
        exit(-1);
    }

    memset(buffer, 0x55, sizeof(buffer));

    ret = write(fd, buffer, 4);
    if(-1 == ret){
        perror("write error");
        goto err;
    }

    memset(buffer, 0x00, sizeof(buffer));

    ret = lseek(fd, -4, SEEK_END);
    if(-1 == ret){
        perror("lseek error");
        goto err;
    }

    ret = read(fd, buffer, 4);
    if(-1 == ret){
        perror("read error");
        goto err;
    }

    printf("0x%x, 0x%x, 0x%x, 0x%x\n", buffer[0],buffer[1],buffer[2],buffer[3]);

    ret = 0;

    err:
        close(fd);
        exit(ret);

}